﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using DAO;

namespace FDeal.PH_Admin
{
    public partial class Admin_ChinhSuaDoanhNgiep : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                if(Request.QueryString["id"] == null)
                {
                    Response.Redirect("~/PH_Admin/Admin_DoanhNghiep.aspx");
                }
                else
                {
                    LoadDuLieu();
                }
            }
        }
  
        public static THONGTINTAIKHOAN tttk = new THONGTINTAIKHOAN();
        public static TAIKHOANDOANHNGHIEP taiKhoangDoanhNghiep;
        String sIDTaiKhoangDoanhNghiep;
        public void LoadDuLieu()
        {
            ThongTinTaiKhoanBUS ttBUS = new ThongTinTaiKhoanBUS();
            tttk = ttBUS.ChiTietname(tbDNTenTaiKhoan.Text);

            sIDTaiKhoangDoanhNghiep = Request.QueryString["id"].ToString();
            TaiKhoanDoanhNghiepBUS taiKhoangDoanhNghiepBUS = new TaiKhoanDoanhNghiepBUS();
            taiKhoangDoanhNghiep = taiKhoangDoanhNghiepBUS.ChiTiet(sIDTaiKhoangDoanhNghiep);

            tbTenDoanhNghiep.Text = taiKhoangDoanhNghiep.TENDN;
            tbMoTaDoanhNghiep.Text = taiKhoangDoanhNghiep.MOTA;
            tbDiaChi.Text = taiKhoangDoanhNghiep.DIACHI;
            tbSDT.Text = taiKhoangDoanhNghiep.SDT;

            ThongTinTaiKhoanBUS thongtindoangnghiepBUS = new ThongTinTaiKhoanBUS();
            THONGTINTAIKHOAN thongtindoangnghiep = thongtindoangnghiepBUS.ChiTiet(taiKhoangDoanhNghiep.IDTAIKHOAN);
            tbDNTenTaiKhoan.Text = thongtindoangnghiep.TENDANGNHAP;
            tbDNMatKhau.Text = thongtindoangnghiep.MATKHAU;
            tbDNNhapLaiMatKhau.Text = thongtindoangnghiep.MATKHAU;
        }

        protected void btCanelDoanhNghiep_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/PH_Admin/Admin_DoanhNghiep.aspx");
        }

        protected void btThayDoiDoanhNghiep_Click(object sender, EventArgs e)
        {
            TaiKhoanDoanhNghiepBUS taiKhoangDoanhNghiepBUS = new TaiKhoanDoanhNghiepBUS();
            taiKhoangDoanhNghiep.TENDN = tbTenDoanhNghiep.Text;
            taiKhoangDoanhNghiep.MOTA = tbMoTaDoanhNghiep.Text;
            taiKhoangDoanhNghiep.DIACHI = tbDiaChi.Text;
            taiKhoangDoanhNghiep.SDT = tbSDT.Text;

            ThongTinTaiKhoanBUS ttBUS = new ThongTinTaiKhoanBUS();
            tttk.TENDANGNHAP = tbDNTenTaiKhoan.Text;
            tttk.MATKHAU = tbDNMatKhau.Text;
            ttBUS.Sua(tttk);

            taiKhoangDoanhNghiepBUS.Sua(taiKhoangDoanhNghiep);
            Response.Redirect("~/PH_Admin/Admin_DoanhNghiep.aspx");
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alertMe();", true);
            //Response.Redirect("~/PH_Admin/Admin_DoanhNghiep.aspx");
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            TaiKhoanDoanhNghiepBUS taiKhoangDoanhNghiepBUS = new TaiKhoanDoanhNghiepBUS();
            taiKhoangDoanhNghiep = taiKhoangDoanhNghiepBUS.ChiTiet(sIDTaiKhoangDoanhNghiep);
            taiKhoangDoanhNghiepBUS.Xoa(taiKhoangDoanhNghiep);
        }
      
    }
}